using System;
using System.Web;
using System.Web.UI;
using System.Collections;
using System.Web.UI.WebControls;

namespace WroxControls 
{

   public class ICollectionLister : WebControl, INamingContainer
											        // Step 3
   {

		ICollection _datasource;


		public ICollection DataSource
		{
			get { return _datasource; }
			set { _datasource = value; }
		}

		Style _headingStyle = new Style();

		public Style HeadingStyle
		{
			get{ return _headingStyle; }
		}

		Style _itemStyle = new Style();

		public Style ItemStyle
		{
			get{ return _itemStyle; }
		}

      protected override void CreateChildControls()
      {
			IEnumerator e;
			Label l;

			// Create the heading, using the specified user style

			l = new Label();
			l.ApplyStyle( _headingStyle );
			l.Text = "ICollection Lister Control";
			Controls.Add( l );

			// Create an label for each key/value pair in the collection

			if ( _datasource == null )
				throw new Exception("Control requires a data source");

			e = _datasource.GetEnumerator();

			while( e.MoveNext() )
			{
				l = new Label();
				l.ApplyStyle( _itemStyle );
				l.Text = "<BR>" + e.Current.ToString();
				Controls.Add( l );
			}
		}
   }
};

